<template>
	<view class="shop">
		<view class="shop-top">
			<view class="shop-top-center">
				<view class="shop-top-1">
					<view class="shop-top-left">
						<image class="shop-top-1-img" v-if="msg_data.agentImage"
							@click="previewImage(msg_data.agentImage, index)" :src=msg_data.agentImage mode="">
						</image>
						<image class="shop-top-1-img" v-else src="https://www.zzzsyh.com/applets/agent/agent/shop.png"
							mode=""></image>
						<view class="shop-top-1-right">
							<!-- <view class="shop-top-1-right-txt">
								浏览量{{msg_data.agentPageviews | changeagentPageviews}}
							</view> -->
							<!-- <view class="shop-top-1-right-txt">
								1355
							</view> -->
						</view>
					</view>
					<view class="shop-top-right">
						<view class="shop-top-1-center" v-if="msg_data && msg_data.agentCompanyName"
							@click="cli_goShopEdit">
							<view class="shop-top-1-center-title">
								{{msg_data.agentCompanyName}}
							</view>
							<!-- <view class="shop-top-1-center-star">
								<text class="shop-top-1-center-txt">评价</text>
								<uni-rate class="shop-top-1-center-star-star" size=22 v-model="value_star" readonly />
							</view> -->
							<view class="shop-top-3" v-if="msg_data.agentContent">
								<view class="shop-top-3-left">
									主营产品：
								</view>
								<view class="shop-top-3-right">
									{{msg_data.agentContent}}
								</view>
							</view>
							<view class="shop-top-2" v-if="msg_data.serviceName && msg_data.serviceName.length > 0">
								<view class="shop-top-2-left">
									服务承诺：
								</view>
								<view class="shop-top-2-right">
									<text class="shop-top-2-right-txt" v-if="msg_data.serviceName.length > 0"
										v-for="(item, index) in changeserviceName(msg_data.serviceName)"
										:key="index">{{item}}</text>
									<text class="shop-top-2-right-txt" v-else>暂无</text>
								</view>
								<image class="shop-top-2-right-img"
									src="https://www.zzzsyh.com/applets/agent/agent/right-four.png" mode="">
								</image>
							</view>
						</view>
						<view class="" v-else>
							<view class="shop-top-right-no" @click="cli_goShopEdit">
								<text>完善信息</text>
								<image class="shop-top-right-no-img"
									src="https://www.zzzsyh.com/applets/agent/agent/right-2.png" mode="">
								</image>
							</view>
						</view>
					</view>
				</view>


				<view class="shop-top-4" v-if="msg_data.agentProvinceName">
					<image class="shop-top-4-img" src="https://www.zzzsyh.com/applets/agent/agent/address.png" mode="">
					</image>
					<text class="shop-top-4-txt">{{msg_data.agentProvinceName}}{{msg_data.agentCityName}}{{msg_data.agentDistrictName}}{{msg_data.agentAddress}}</text>
				</view>
			</view>

		</view>
		<view class="shop-main">
			<view class="shop-main-head">
				<view class="shop-main-head-left">
					<text @click="cli_nav(1)" class="shop-main-head-txt"
						:class="[isShow == 1? 'shop-main-head-txt-change' : '']">已上架</text>
					<!-- <text class="shop-main-head-txt" >已下架</text> -->
					<text @click="cli_nav(0)" class="shop-main-head-txt shop-main-head-txt2"
						:class="[isShow == 0? 'shop-main-head-txt-change' : '']">待上架</text>
				</view>
				<view class="shop-main-head-right" @click="cli_addNew">
					<!-- <image class="shop-main-head-right-back" src="https://www.zzzsyh.com/applets/agent/agent/shop_1.png" mode=""></image> -->
					<image class="shop-main-head-right-img"
						src="https://www.zzzsyh.com/applets/agent/agent/shop_2_2.png" mode=""></image>
					<text class="shop-main-head-right-txt font_blod">新增产品</text>
				</view>
			</view>
			<view class="shop-main-main" v-if="list && list.length > 0">
				<view class="shop-main-main-li" v-for="(item, index) of list" :key="index">
					<image class="shop-main-main-li-img" @click="previewImage(item.partsImages, index)"
						:src=item.partsImages mode=""></image>
					<view class="shop-main-main-li-main">
						<view class="shop-main-main-li-main-top">
							<text class="shop-main-main-li-main-title font_blod">{{item.partsName}}</text>
							<image @click="cli_model_all(item)" class="shop-main-main-li-main-top-img"
								src="https://www.zzzsyh.com/applets/agent/agent/right_five.png" mode=""></image>
						</view>
						<view class="shop-main-main-li-main-id">
							ID: {{item.id}}
						</view>
						<view class="shop-main-main-li-main-btm">
							<view class="shop-main-main-li-main-top-right">
								<text class="shop-main-main-li-main-m">￥</text>
								<text class="shop-main-main-li-main-money">{{item.minPrice}}-{{item.maxPrice}}</text>
								<text class="shop-main-main-li-main-unit">/{{item.partsUnit}}</text>
							</view>

							<!-- <view class="shop-main-main-li-main-btm-right">
								<text class="shop-main-main-li-main-btm-right-txt">分享</text>
								<image class="shop-main-main-li-main-btm-right-img" src="" mode=""></image>
							</view> -->
						</view>
						<view class="shop-main-main-li-main-btm-left">
							<text class="shop-main-main-li-main-btm-left-txt2 font_blod" @click="cli_edit(item)">编辑</text>
							<!-- <text>立即下架</text> -->
							<text @click="updatePartsIsShow(item.id, 0)" class="shop-main-main-li-main-btm-left-txt3 font_blod"
								v-if="isShow == 1">立即下架</text>
							<text @click="updatePartsIsShow(item.id, 1)" class="shop-main-main-li-main-btm-left-txt3 font_blod"
								v-if="isShow == 0">立即上架</text>
							<!-- <text>查看型号</text> -->
						</view>
					</view>
				</view>
			</view>
			<view class="shop-main-main" v-else>
				<view class="yPopNone">
					<image style="margin-top: 20rpx;" class="yPopNoneImg"
						src="https://www.zzzsyh.com/applets/agent/factory/23.png" mode="">
					</image>
					<view class="yPopNoneTxt">
						暂无产品~
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				msg_data: {
					agentWximage: '',
					agentPageviews: '',
					agentCompanyName: '',
					agentContent: '',
					serviceName: [],
					agentProvinceName: '',
					agentCityName: '',
					agentDistrictName: '',
					agentAddress: ''
				}, // 会长信息
				agentId: uni.getStorageSync('agentId'),
				isShow: '1', // 1上架 0下架
				value_star: 3.5,
				list: []
			}
		},
		onShow() {
			this.getAgentPartsList()
			// 获取会长信息，店铺信息
			this.getAgentInfoById()
		},
		mounted() {

		},
		methods: {
			cli_nav(val) {
				this.isShow = val
				this.getAgentPartsList()
			},
			// 更改服务承诺
			changeserviceName(val) {
				if (val) {
					return val.slice(0, 3)
				} else {
					return []
				}
			},
			// 图片预览
			previewImage(item, index) {
				console.log(item);
				let lis = item.split()
				wx.previewImage({
					current: 0, // 当前显示图片的http链接
					urls: lis // 需要预览的图片http链接列表
				})
			},
			// 跳转编辑店铺
			cli_goShopEdit() {
				uni.navigateTo({
					url: '/pages/shopEdit/shopEdit'
				})
			},
			// 点击编辑产品
			cli_edit(item) {
				let id = item.id
				uni.navigateTo({
					url: '/pages/shopEditProduct/shopEditProduct?id=' + id
				})
			},
			// 点击查看全部型号
			cli_model_all(item) {
				let id = item.id
				uni.navigateTo({
					url: '/pages/shopModelAll/shopModelAll?id=' + id
				})
			},
			// 点击新增产品
			cli_addNew() {
				uni.navigateTo({
					url: '/pages/shopAddProduct/shopAddProduct'
				})
			},
			// 产品上架下架
			updatePartsIsShow(id, isShow) {
				// let dd = this.isShow
				// let isShow = dd == 1? '0': '1'
				let _that = this
				uni.request({
					url: allapi.updatePartsIsShow,
					data: {
						id: id,
						isShow: isShow
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						_that.getAgentPartsList()
					}
				})
			},
			// 获取会长店铺产品列表
			getAgentPartsList() {
				uni.request({
					url: allapi.getAgentPartsList,
					data: {
						agentId: this.agentId,
						isShow: this.isShow
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						this.list = dat
					}
				})
			},
			// 获取会长信息，店铺信息
			getAgentInfoById() {
				uni.request({
					url: allapi.getAgentInfoById,
					data: {
						agentId: this.agentId,
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						console.log(dat);
						this.msg_data = dat
					}
				})
			}
		}
	}
</script>

<style scoped>
	.shop {
		position: absolute;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.shop-top {
		/* height: 380rpx; */
		background: #FFFFFF;
		/* margin: 0 18rpx; */
		background: linear-gradient(180deg, #28CD50 0%, rgba(243, 245, 246, 0.79) 100%);
		padding: 24rpx;
	}

	.shop-top-center {
		background: #FFFFFF;
		padding: 24rpx 16rpx;
		border-radius: 16rpx;
	}

	.shop-top-left {
		width: 120rpx;
	}

	.shop-top-right {
		flex: 1;
	}

	.shop-top-right-no {
		width: 196rpx;
		height: 72rpx;
		background: #F3F5F6;
		border-radius: 16rpx;
		margin-left: 16rpx;
		margin-top: 24rpx;
		color: #666666;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.shop-top-right-no-img {
		width: 40rpx;
		height: 40rpx;
	}

	.shop-top-1 {
		/* height: 172rpx; */
		/* margin-top: 14rpx; */
		display: flex;
	}

	.shop-top-1-img {
		width: 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		/* margin-left: 10rpx; */
		background: #EEEEEE;
	}

	.shop-top-1-center {
		flex: 1;
		margin-left: 16rpx;
		/* margin-top: 18rpx; */
		/* height: 50rpx; */
	}

	.shop-top-1-center-title {
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}

	.shop-top-1-center-txt {
		font-size: 28rpx;
		color: #333333;
	}

	.shop-top-1-center-star {
		display: flex;
		align-items: center;
		margin-top: 12rpx;
	}

	.shop-top-1-center-star-star {
		margin-left: 20rpx;
	}

	.shop-top-1-right {}

	.shop-top-1-right-txt {
		height: 28rpx;
		line-height: 28rpx;
		font-size: 20rpx;
		color: #999999;
		text-align: center;
	}

	.shop-top-2 {
		display: flex;
		align-items: center;
		margin-top: 18rpx;
		height: 40rpx;
	}

	.shop-top-2-left {
		width: 120rpx;
		font-size: 24rpx;
		color: #BBBBBB;
		/* margin-left: 22rpx; */
	}

	.shop-top-2-right {
		flex: 1;
		margin-left: 4rpx;
	}

	.shop-top-2-right-txt {
		/* width: 124rpx;
		height: 40rpx; */
		border-radius: 6rpx;
		font-size: 24rpx;
		color: #41CA5B;
		background: #EFFBE4;
		border-radius: 8px;
		text-align: center;
		line-height: 40rpx;
		margin-left: 8rpx;
		padding: 6rpx 8rpx;
	}

	.shop-top-2-right-img {
		width: 40rpx;
		height: 40rpx;
	}

	.shop-top-3 {
		display: flex;
		margin-top: 10rpx;
	}

	.shop-top-3-left {
		width: 120rpx;
		font-size: 24rpx;
		color: #BBBBBB;
		/* margin-left: 22rpx; */
	}

	.shop-top-3-right {
		flex: 1;
		margin-left: 10rpx;
		font-size: 24rpx;
		color: #333333;
		/* margin-right: 80rpx; */
	}

	.shop-top-4 {
		margin-top: 30rpx;
		display: flex;
		align-items: center;
		background: #F3F5F6;
		border-radius: 16rpx;
		padding: 24rpx;
	}

	.shop-top-4-img {
		width: 32rpx;
		height: 32rpx;
		/* margin-left: 22rpx; */
		/* background: red; */
	}

	.shop-top-4-txt {
		font-size: 24rpx;
		color: #666666;
		margin-left: 24rpx;
	}

	.shop-main {
		flex: 1;
		background: #FFFFFF;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		padding: 0 48rpx;
	}

	.shop-main-head {
		height: 104rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.shop-main-head-left {
		display: flex;
		/* margin-left: 14rpx; */
		margin-top: 20rpx;
	}

	.shop-main-head-txt {
		width: 100rpx;
		height: 72rpx;
		line-height: 72rpx;
		border-bottom: 8rpx solid #FFFFFF;
		font-size: 28rpx;
		color: #999999;
		display: block;
		/* margin: 0 24rpx; */
		text-align: center;
		border-radius: 4rpx;
	}

	.shop-main-head-txt2 {
		margin-left: 104rpx;
	}

	.shop-main-head-txt-change {
		border-color: #37C67A;
		color: #333333;
	}

	.shop-main-head-right {
		width: 208rpx;
		height: 60rpx;
		background: linear-gradient(180deg, #FBC268 0%, #FC9B3E 100%);
		border-radius: 30rpx;
		display: flex;
		align-items: center;
		margin-right: 24rpx;
	}

	.shop-main-head-right-back {
		width: 222rpx;
		height: 104rpx;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 1;
	}

	.shop-main-head-right-img {
		/* position: absolute; */
		width: 40rpx;
		height: 40rpx;
		margin-left: 20rpx;
	}

	.shop-main-head-right-txt {
		font-size: 24rpx;
		color: #FFFFFF;
		margin-left: 16rpx;
	}

	.shop-main-main {
		overflow: auto;
	}

	.shop-main-main-li {
		/* height: 150rpx; */
		margin-bottom: 24rpx;
		display: flex;
		padding-top: 40rpx;
		padding-bottom: 20rpx;
		border-bottom: 2rpx solid #EEEEEE;
	}

	.shop-main-main-li-img {
		width: 184rpx;
		height: 184rpx;
		background: #eeeeee;
		border-radius: 8rpx;
	}

	.shop-main-main-li-main {
		flex: 1;
		margin-left: 40rpx;
	}

	.shop-main-main-li-main-top {
		display: flex;
		align-items: center;
		height: 50rpx;
	}

	.shop-main-main-li-main-title {
		font-size: 28rpx;
		color: #333333;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.shop-main-main-li-main-top-img {
		width: 40rpx;
		height: 40rpx;
	}

	.shop-main-main-li-main-top-right {
		display: flex;
		font-weight: 500;
		color: #EF691C;
		align-items: center;
		/* margin-left: 40rpx; */
	}

	.shop-main-main-li-main-m {
		font-size: 28rpx;
	}

	.shop-main-main-li-main-money {
		font-size: 36rpx;
	}

	.shop-main-main-li-main-unit {
		margin-left: 8rpx;
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
	}

	.shop-main-main-li-main-id {
		font-size: 24rpx;
		color: #AAAAAA;
		margin-top: 16rpx;
		height: 34rpx;
	}

	.shop-main-main-li-main-btm {
		/* height: 44rpx; */
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		margin-top: 18rpx;
	}

	.shop-main-main-li-main-btm-left {
		font-size: 28rpx;
		color: #F58600;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		margin-top: 20rpx;
	}

	.shop-main-main-li-main-btm-left-txt2 {
		display: block;
		width: 92rpx;
		height: 50rpx;
		border-radius: 27rpx;
		border: 2rpx solid #333333;
		line-height: 54rpx;
		text-align: center;
		color: #333333;
		font-size: 20rpx;
	}

	.shop-main-main-li-main-btm-left-txt3 {
		display: block;
		margin-left: 24rpx;
		width: 132rpx;
		height: 54rpx;
		line-height: 54rpx;
		text-align: center;
		background: linear-gradient(90deg, #2ACE52 0%, #1DC248 100%);
		border-radius: 27rpx;
		font-size: 20rpx;
		color: #FFFFFF;
	}

	.shop-main-main-li-main-btm-right {
		width: 124rpx;
		height: 40rpx;
		border: 2px solid #DDDDDD;
		border-radius: 22rpx;
		font-size: 28rpx;
		color: #BBBBBB;
		display: flex;
		align-items: center;
		justify-content: space-between;

	}

	.shop-main-main-li-main-btm-right-txt {
		margin-left: 16rpx;
	}

	.shop-main-main-li-main-btm-right-img {
		width: 40rpx;
		height: 40rpx;
		background: red;
		margin-right: 4rpx;
	}
</style>
